package com.ujson.chat.client.command;

import com.ujson.base.common.utils.LogUtil;
import com.ujson.chat.common.enums.ConsoleCommandType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Scanner;

/**
 * <h3>ujson-parent</h3>
 * <p>控制台登出命令</p>
 *
 * @author JerryLiu  a1031757312@gmail.com
 * @version 1.0
 * @date 2021-11-22 21:26
 */
@Slf4j
@Service
public class LogoutConsoleCommand extends ConsoleCommand<String> {

    private static final String logoutPattern = "\\S+";

    public ConsoleCommandType getType() {
        return ConsoleCommandType.LOGOUT;
    }

    @Override
    public String getInput() {
        return this.getInputString();
    }

    @Override
    public String getMatchPattern() {
        return logoutPattern;
    }

    @Override
    public void exec(Scanner scanner) {
        LogUtil.info(log, "client will logout for uid: " + getClientSession().getUserDto().getUid());
        while (!checkCommand(this.setInputString(scanner.next()))) {
            System.err.println("菜单命令输入不正确, 请重新输入:");
        }

        LogUtil.info(log, "logout input: " + getInput());
        this.doLogout();
    }

    public void doLogout() {

    }
}
